package com.project.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.DailyBean;
import com.project.bean.ProductBean;
import com.project.mapper.IDailyMapper;
import com.project.mapper.IProductMapper;
import com.project.service.IDailyService;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class ProductServiceImpl implements IProductService {
    @Autowired
    private IProductMapper productMapper;

    @Override
    public List<ProductBean> findBySupplierId(int supplierId) {
        return productMapper.findBySupplierId(supplierId);
    }

    @Override
    public void addProduct(int supplierId, ProductBean product) {
        productMapper.addProduct(supplierId,product);
    }

    /**
     * 按id删除商品（修改供应商外键为0）
     * @param id 商品id
     */
    @Override
    public void delById(int id) {
        productMapper.delById(id);
    }

    @Override
    public void buyProduct(int id, int num) {
        productMapper.buyProduct(id,num);
    }

    @Override
    public PageInfo<ProductBean> findByItem(int pn, int pageSize, String name, String type, Integer startNum, Integer endNum) {
        PageHelper.startPage(pn,pageSize);
        return PageInfo.of(productMapper.findByItem(name,type,startNum,endNum));
    }

    @Override
    public ProductBean findById(int id) {
        return productMapper.findById(id);
    }

    @Override
    public void update(int id, int price) {
        productMapper.update(id,price);
    }

    @Override
    public PageInfo<ProductBean> findSellProductByItem(int pn, int pageSize, String factory, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(pn,pageSize);
        return PageInfo.of(productMapper.findSellProductByItem(factory,startDate,endDate));
    }
}
